/*
 * File:   util.cpp
 * Author: dolphinigle
 *
 * Created on December 2, 2011, 5:57 PM
 */

#include "util.h"

#include <cstdio>
#include <string>
using std::string;

bool IsFileName(const string& path) {
  if (path == "") return false;
  return !IsDirectoryName(path);
}
bool IsDirectoryName(const string& path) {
  if (path == "") return false;
  return path[path.size() - 1] == '/';
}

string IntToString(int i) {
  char buffer[12];
  sprintf(buffer, "%d", i);
  return buffer;
}

int StringToInt(string str) {
  int hasil;
  sscanf(str.c_str(), "%d", &hasil);
  return hasil;
}

string GetFolder(string path) {
  int slash_lc = 0;
  for (int i = path.size() - 2; i >= 0; --i) {
    if (path[i] == '/') {
      slash_lc = i;
      break;
    }
  }
  return path.substr(0, slash_lc + 1);
}
